https://leetcode.cn/problems/n-queens/
class Solution {
public:
    bool checkcol[10],checkdig1[20],checkdig2[20];
    vector<vector<string>> ret;
    vector<string> path;
    int _n;

    void dfs(int row)
    {
        if(row==_n)
        {
            ret.push_back(path);
            return ;
        }

        for(int col=0;col<_n;col++)
        {
            //存在剪枝
            if(!checkcol[col]&&!checkdig1[col-row+_n]&&!checkdig2[col+row])
            {
                path[row][col]='Q';
                checkcol[col]=true;
                checkdig1[col-row+_n]=true;checkdig2[col+row]=true;
                dfs(row+1);
                //恢复现场
                checkcol[col]=false;
                checkdig1[col-row+_n]=false;checkdig2[col+row]=false;
                path[row][col]='.';
            }
        }

    }
    vector<vector<string>> solveNQueens(int n) {
        path.resize(n);
        _n=n;
        for(int i=0;i<n;i++)
            path[i].append(n,'.');

        dfs(0);
        return ret;
    }
};